package com.mipo.quartz;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.util.concurrent.*;

@Configuration
@EnableAsync
public class ThreadPool {

	public ThreadPool() {
		System.out.println("kkkkkkkkkkkk");
	}
	
    public Integer j_pool_size = 2;
    public Integer l_pool_size = 1;
    public Integer t_pool_size = 10;

    @Bean
    public ThreadPoolTaskExecutor eExecutor() {
        return getPoolExecutor(j_pool_size, "swap-job-T-");
    }
    @Bean
    public ThreadPoolTaskExecutor lExecutor() {
        return getPoolExecutor(l_pool_size, "swap-log-T-");
    }
    @Bean
    public ThreadPoolTaskExecutor tExecutor() {
        return getPoolExecutor(t_pool_size, "swap-task-T-");
    }
    @Bean
    public ThreadPoolTaskScheduler schedulerExecutor() {
        return new ThreadPoolTaskScheduler();
    }
    public ThreadPoolTaskExecutor getPoolExecutor(Integer corePoolSize, String namePrefix) {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(corePoolSize);
        executor.setThreadNamePrefix(namePrefix);
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}
